<?php

namespace app\data\controller\api;

use think\admin\Controller;

/**
 * 帮助中心接口控制器
 * Class News
 * @package app\data\controller\api
 */
class Help extends Controller
{
    /**
     * 获取帮助中心内容列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $query = $this->_query('DataHelpItem');
        $query->where(['status' => 1, 'deleted_at' => null, ])->withoutField('content,updated_at,deleted_at');
        $result = $query->order('sort desc,id desc')->page(true, false, false, 100);
        $this->success('获取帮助中心内容列表成功', $result);
    }

    /**
     * 获取帮助中心详情
     * @param $id
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function detail($id)
    {
        $result = $this->app->db->name('DataHelpItem')->field('id,name,content,sort,created_at')->find($id);
        if ($result) {
            $this->success('获取帮助中心详情成功', $result);
        } else {
            $this->error('获取帮助中心详情失败', $result);
        }
    }

}